package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.pojo.NewStu;
import com.example.demo.serviec.StuService;

@RestController
@RequestMapping("db")
public class DBController {

	@Autowired
	private StuService stuService;
	
	@RequestMapping("/getall")
	public List<NewStu> getStu() {
		
		return stuService.getStu();
	}
	
	@RequestMapping("/insert")
	public String saveStu(NewStu stu) throws Exception {	
		if (stu != null) { 
			stuService.insertStu(stu);
			return "插入成功";
		}
		else {
			return "插入失败";
		}
	}
	
	@RequestMapping("/update")
	public String updateStu(NewStu stu) {
		if (stu != null) {
			stuService.updateStu(stu);
			return "更新成功";
		}
		else {
			return "更新失败";
		}
	}
	
	@RequestMapping("/delete")
	public String deleteStu(NewStu stu) {
		if (stu != null) {
			stuService.deleteStu(stu);
			return "删除成功";
		}
		else {
			return "删除失败";
		}
	}
	
	
}
